// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
mod service;
mod tools;
use serde_json::{json, Value};
use service::*;

#[tauri::command]
async fn get_bili_url(iframe: String, cookie: String) -> Value {
    match biliservice::get_bili_url(&iframe, &cookie).await {
        Ok(url) => {
            json!({
                "code":"0",
                "url":url,
                "message":"success"
            })
        }
        Err(b) => {
            json!({
                "code":"-1",
                "message":b.to_string()
            })
        }
    }
    //String::new()
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![get_bili_url])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
